// AppTabCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "CStudyChinese.h"
#include "AppTabCtrl.h"
#include "Option.h"
#include "DlgSysSetting.h"
#include "DlgFaceSetting.h"
#include "FaceManager.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAppTabCtrl

CAppTabCtrl::CAppTabCtrl()
{
	::ZeroMemory(&m_tabPages, sizeof(m_tabPages));

	m_tabPages[0]=new COption;
	m_tabPages[1]=new CDlgSysSetting;
	m_tabPages[2]=new CDlgFaceSetting;

	m_nNumberOfPages=3;
}

CAppTabCtrl::~CAppTabCtrl()
{
	for(int nCount=0; nCount < m_nNumberOfPages; nCount++)
	{
		delete m_tabPages[nCount];
	}
}


BEGIN_MESSAGE_MAP(CAppTabCtrl, CEnTabCtrl)
	//{{AFX_MSG_MAP(CAppTabCtrl)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAppTabCtrl message handlers

void CAppTabCtrl::SetRectangle()
{
    CRect tabRect, itemRect;
	int nX, nY, nXc, nYc;

	GetClientRect(&tabRect);
	GetItemRect(0, &itemRect);

	nX=itemRect.left;
	nY=itemRect.bottom+1;
	nXc=tabRect.right-itemRect.left-1;
	nYc=tabRect.bottom-nY-1;

	m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
	for(int nCount=1; nCount < m_nNumberOfPages; nCount++){
		m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
	}
}

void CAppTabCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{	
	CEnTabCtrl::OnLButtonDown(nFlags, point);

	if(m_tabCurrent != GetCurFocus())
	{
		m_tabPages[m_tabCurrent]->ShowWindow(SW_HIDE);
		m_tabCurrent=GetCurFocus();
		m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW);
		m_tabPages[m_tabCurrent]->SetFocus();
	}
}

void CAppTabCtrl::Init()
{
	m_tabCurrent=0;

	m_tabPages[0]->Create(IDD_DIALOG1, this);
	m_tabPages[1]->Create(IDD_DLG_SYSSETTING, this);
	m_tabPages[2]->Create(IDD_DLG_FACESETTING, this);

	m_tabPages[0]->ShowWindow(SW_SHOW);
    for(int nCount=1; nCount < m_nNumberOfPages; nCount++)
	{
		m_tabPages[nCount]->ShowWindow(SW_HIDE);
	}
	
	SetRectangle();
}

void CAppTabCtrl::SaveUpdateSetting()
{
    for(int nCount=0; nCount < m_nNumberOfPages; nCount++)
	{
		m_tabPages[nCount]->SaveUpdateSetting();
	}
}

void CAppTabCtrl::UpdateFace()
{
    for(int nCount=0; nCount < m_nNumberOfPages; nCount++)
	{
		m_tabPages[nCount]->UpdateFace();
		m_tabPages[nCount]->InvalidateRect(NULL);
	}
}
